#ifndef SOCKETS_ISocketHandler_H
#define SOCKETS_ISocketHandler_H
#include "socket_include.h"
#include "Socket.h"

class ISocketHandler
{
friend class Socket;
public:
	typedef enum {
		ReadMode,
		WriteMode,
		RWMode,
	} SelectMode;

	virtual ~ISocketHandler() {}
	/** Add socket instance to socket map. Removal is always automatic. */
	virtual void Add(Socket *) = 0;

	/** Get status of read/write/exception file descriptor set for a socket. */
	virtual void Get(SOCKET s,bool& r,bool& w) = 0;

	/** Wait for events, generate callbacks. */
	virtual int Select(long sec, long usec, SelectMode mode = RWMode) = 0;
	/** This method will not return until an event has been detected. */
	virtual int Select(SelectMode mode = RWMode) = 0;
	/** Wait for events, generate callbacks. */
	virtual int Select(struct timeval *tsel, SelectMode mode = RWMode) = 0;

	/** Check that a socket really is handled by this socket handler. */
	virtual bool Valid(Socket *) = 0;
	/** Return number of sockets handled by this handler.  */
	virtual size_t GetCount() = 0;
private:
	/** Remove socket from socket map, used by Socket class. */
	virtual void Remove(Socket *) = 0;	
};
#endif // SOCKETS_ISocketHandler_H
